package com.kajespero.domain.commons.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.kajespero.dao.commons.ReadWriteDAO;
import com.kajespero.domain.commons.ReadWriteDomain;
import com.kajespero.vo.IdentifierVO;

public abstract class AbstractReadWriteDomain<D extends ReadWriteDAO<T, Id>, T extends IdentifierVO<Id>, Id extends Comparable<Id>> extends AbstractReadDomain<D, T, Id> implements ReadWriteDomain<D, T, Id>{

	private static final Log LOG = LogFactory.getLog(AbstractReadWriteDomain.class);
	
	@Override
	public void saveOrUpdade(T instance) {
		getDAO().saveOrUpdate(instance);
	}

	@Override
	public void delete(T instance) {
		getDAO().delete(instance);
	}

	@Override
	public void delete(Id identifier) {
		getDAO().delete(identifier);
	}

	@Override
	public T createNewBean(){
		try {
			return getDAO().createNewBean();
		} catch (InstantiationException e) {
			LOG.error("InstantiationException : " + e.getMessage(), e);
		} catch (IllegalAccessException e) {
			LOG.error("IllegalAccessException : " + e.getMessage(), e);
		}
		return null;
	}
}
